package com.muqi.app.im.widget;

import com.muqi.app.qlearn.student.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public class HomeWkDialog extends PopupWindow implements OnClickListener {
	private View conentView;
	protected Context mContext;
	private int selectPosition;
	private OnClickMenuListener listener = null;
	
	public interface OnClickMenuListener{
		void onClickMenu(int code, int position);
	}
	
	@SuppressLint("InflateParams") @SuppressWarnings("deprecation")
	public HomeWkDialog(final Activity context, OnClickMenuListener listener) {
		this.mContext = context;
		this.listener = listener;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		conentView = inflater.inflate(R.layout.popup_dialog_homework, null);
		//int h = context.getWindowManager().getDefaultDisplay().getHeight();
		int w = context.getWindowManager().getDefaultDisplay().getWidth();
		this.setContentView(conentView);
		this.setWidth(w/3+110);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setOutsideTouchable(true);
		this.update();
		ColorDrawable dw = new ColorDrawable(0000000000);
		this.setBackgroundDrawable(dw);
		this.setAnimationStyle(R.style.AnimationPreview);
		LinearLayout button1 = (LinearLayout) conentView.findViewById(R.id.pop_homewk_delete);
		LinearLayout button2 = (LinearLayout) conentView.findViewById(R.id.pop_homewk_copy);
		LinearLayout button3 = (LinearLayout) conentView.findViewById(R.id.pop_homewk_share);
		button1.setOnClickListener(this);
		button2.setOnClickListener(this);
		button3.setOnClickListener(this);
	}

	/**   
	 * showPopupWidow
	 * @param parent
	 */
	public void showPopupWindow(View parent, int position) {
		selectPosition = position;
		if (!this.isShowing()) {
			this.showAsDropDown(parent, 0 , 5);
		} else {
			this.dismiss();
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.pop_homewk_delete:
			listener.onClickMenu(1, selectPosition);
			break;
		case R.id.pop_homewk_copy:
			listener.onClickMenu(2, selectPosition);
			break;
		case R.id.pop_homewk_share:
			listener.onClickMenu(3, selectPosition);
			break;
		default:
			break;
		}
		this.dismiss();
	}
}
